import { SelectProps } from 'antd';

import ApiIcon from '@/assets/icons/node-api.svg';
import DataLoadIcon from '@/assets/icons/node-data-load.svg';
import DataModifyIcon from '@/assets/icons/node-data-modify.svg';
import EndNodeIcon from '@/assets/icons/node-end.svg';
import ManualIcon from '@/assets/icons/node-manual.svg';
import RuleIcon from '@/assets/icons/node-rule.svg';
import StartNodeIcon from '@/assets/icons/node-start.svg';

export const TOKEN_STORAGE_KEY = 'token_1';

export const varTypeList: Record<string, any> = {
  STRING: '字符串',
  INTEGER: '整数',
  DECIMAL: '小数',
  DATE_TIME: '日期时间',
  BOOLEAN: '布尔值',
  DATE: '日期',
  ENUM: '枚举'
};

export enum EOperator {
  Eq = 'EQ',
  Ge = 'GE',
  Gt = 'GT',
  In = 'IN',
  IsEmpty = 'IS_EMPTY',
  IsNotEmpty = 'IS_NOT_EMPTY',
  LE = 'LE',
  Like = 'LIKE',
  Lt = 'LT',
  Neq = 'NEQ',
  NotIn = 'NOT_IN',
  NotLike = 'NOT_LIKE'
}

export const CACHE_GRAPH_DATA = 'cache_graph_data';

// { label: '', value: '' }
export const varTypeOptions = Object.keys(varTypeList).map((key) => {
  return {
    label: varTypeList[key],
    value: key
  };
});

export enum NODE_TYPE {
  START = 'START',
  END = 'END',
  DATA_LOAD = 'DATA_LOAD',
  API = 'API',
  RULE = 'RULE',
  // 人工审核
  MANUAL = 'MANUAL',
  // 自动处理
  DATA_MODIFY = 'DATA_MODIFY',
  // 边
  BASE_EDGE = 'BASE_EDGE'
}

export type TNodeType = keyof typeof NODE_TYPE;

export const booleanOptions: SelectProps['options'] = [
  { label: '是', value: 'true' },
  { label: '否', value: 'false' }
];

export const NODE_LIST = {
  [NODE_TYPE.START]: {
    nodeName: '开始节点',
    icon: 'node-start',
    iconSvg: StartNodeIcon,
    nextNodeList: [NODE_TYPE.API, NODE_TYPE.DATA_LOAD, NODE_TYPE.DATA_MODIFY, NODE_TYPE.RULE, NODE_TYPE.END]
  },
  [NODE_TYPE.DATA_LOAD]: {
    nodeName: '数据加载',
    icon: 'node-data-load',
    iconSvg: DataLoadIcon,
    nextNodeList: [NODE_TYPE.API, NODE_TYPE.DATA_LOAD, NODE_TYPE.DATA_MODIFY, NODE_TYPE.RULE, NODE_TYPE.MANUAL, NODE_TYPE.END]
  },
  [NODE_TYPE.API]: {
    nodeName: 'API调用',
    icon: 'node-api',
    iconSvg: ApiIcon,
    nextNodeList: [NODE_TYPE.API, NODE_TYPE.DATA_LOAD, NODE_TYPE.DATA_MODIFY, NODE_TYPE.RULE, NODE_TYPE.MANUAL, NODE_TYPE.END]
  },
  [NODE_TYPE.RULE]: {
    nodeName: '规则节点',
    icon: 'node-rule',
    iconSvg: RuleIcon,
    nextNodeList: [NODE_TYPE.API, NODE_TYPE.DATA_LOAD, NODE_TYPE.DATA_MODIFY, NODE_TYPE.MANUAL, NODE_TYPE.END]
  },
  [NODE_TYPE.MANUAL]: {
    nodeName: '人工节点',
    icon: 'node-manual',
    iconSvg: ManualIcon,
    nextNodeList: [NODE_TYPE.API, NODE_TYPE.DATA_LOAD, NODE_TYPE.DATA_MODIFY, NODE_TYPE.RULE, NODE_TYPE.MANUAL, NODE_TYPE.END]
  },
  [NODE_TYPE.DATA_MODIFY]: {
    nodeName: '数据更新',
    icon: 'node-data-modify',
    iconSvg: DataModifyIcon,
    nextNodeList: [NODE_TYPE.API, NODE_TYPE.DATA_LOAD, NODE_TYPE.DATA_MODIFY, NODE_TYPE.RULE, NODE_TYPE.MANUAL, NODE_TYPE.END]
  },
  [NODE_TYPE.END]: {
    nodeName: '结束节点',
    icon: 'node-end',
    iconSvg: EndNodeIcon,
    nextNodeList: []
  },
  [NODE_TYPE.BASE_EDGE]: {
    nodeName: '边',
    icon: 'base-edge',
    iconSvg: null,
    nextNodeList: []
  }
};
